﻿<UserControl x:Class="Waf.MusicManager.Presentation.Views.MusicPropertiesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:p="clr-namespace:Waf.MusicManager.Presentation.Properties"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ctrl="clr-namespace:Waf.MusicManager.Presentation.Controls"
             xmlns:dd="clr-namespace:Waf.MusicManager.Presentation.DesignData"
             xmlns:domain="clr-namespace:Waf.MusicManager.Domain.MusicFiles;assembly=Waf.MusicManager.Domain"
             mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SampleMusicPropertiesViewModel, IsDesignTimeCreatable=True}"
             d:DesignHeight="500" d:DesignWidth="300" Background="{StaticResource DefaultBackground}">
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Content="{x:Static p:Resources.SelectAFile}" BorderThickness="0,0,0,1" Padding="15,7" Grid.Row="0">
            <Label.Style>
                <Style TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
                    <Setter Property="Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding MusicFile}" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>

        <Label Content="{Binding MusicFile.SharedMusicFiles.Count}" ContentStringFormat="{x:Static p:Resources.EditItems}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Padding="15,7" Grid.Row="0">
            <Label.Style>
                <Style TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
                    <Style.Triggers>
                        <Trigger Property="Content" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        <DataTrigger Binding="{Binding MusicFile.SharedMusicFiles.Count}" Value="0">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>

        <Label Content="{Binding MusicFile.FileName, Converter={StaticResource PathToFileNameConverter}}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Padding="15,7" Grid.Row="0">
            <Label.ToolTip>
                <ctrl:SuperToolTip Title="{Binding MusicFile.FileName, Converter={StaticResource PathToFileNameConverter}, ConverterParameter=WithExtension}"
                                   Description="{Binding MusicFile.FileName, Converter={StaticResource PathToDirectoryNameConverter}}"/>
            </Label.ToolTip>
            <Label.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding AutoFillFromFileNameCommand}" Header="{x:Static p:Resources.AutoFillFromFileName}">
                        <MenuItem.Style>
                            <Style TargetType="MenuItem">
                                <Style.Triggers>
                                    <Trigger Property="IsEnabled" Value="False">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Style>
                    </MenuItem>
                    <MenuItem Command="{Binding CopyFileNameCommand}" Header="{x:Static p:Resources.CopyFileName}"/>
                </ContextMenu>
            </Label.ContextMenu>
            <Label.Style>
                <Style TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
                    <Setter Property="Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding MusicFile.SharedMusicFiles.Count}" Value="0">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>

        <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
            <Grid Margin="11">
                <Grid.IsEnabled>
                    <MultiBinding Converter="{StaticResource MusicPropertiesEnabledConverter}">
                        <Binding Path="MusicFile"/>
                        <Binding Path="MusicFile.IsMetadataLoaded"/>
                    </MultiBinding>
                </Grid.IsEnabled>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="{StaticResource Layout.ColumnSpace}"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.LargeRowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.LargeRowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.LargeRowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.LargeRowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="{StaticResource Layout.RowSpace}"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Label Content="{x:Static p:Resources.Artist}" Grid.Column="0" Grid.Row="0"/>
                <TextBox Text="{Binding MusicFile.Metadata.Artists, Converter={StaticResource StringListToStringConverter}}" 
                            AcceptsReturn="True" Grid.Column="2" Grid.Row="0"/>

                <Label Content="{x:Static p:Resources.Title}" Grid.Column="0" Grid.Row="2"/>
                <TextBox Text="{Binding MusicFile.Metadata.Title}" Grid.Column="2" Grid.Row="2"/>

                <Label Content="{x:Static p:Resources.Length}" Grid.Column="0" Grid.Row="4"/>
                <Label Content="{Binding MusicFile.Metadata.Duration, Converter={StaticResource DurationConverter}}" Grid.Column="2" Grid.Row="4"/>

                <Label Content="{x:Static p:Resources.Rating}" Grid.Column="0" Grid.Row="6"/>
                <ctrl:Rating Value="{Binding MusicFile.Metadata.Rating, Converter={StaticResource RatingToStarsConverter}}"
                        Padding="2,0" Grid.Column="2" Grid.Row="6" TickPlacement="TopLeft"/>

                <Label Content="{x:Static p:Resources.Album}" Grid.Column="0" Grid.Row="8"/>
                <TextBox Text="{Binding MusicFile.Metadata.Album}" Grid.Column="2" Grid.Row="8"/>

                <Label Content="{x:Static p:Resources.TrackNo}" Grid.Column="0" Grid.Row="10"/>
                <TextBox Text="{Binding MusicFile.Metadata.TrackNumber, Converter={StaticResource UIntToDisplayValueConverter}}" Grid.Column="2" Grid.Row="10"/>

                <Label Content="{x:Static p:Resources.Year}" Grid.Column="0" Grid.Row="12"/>
                <TextBox Text="{Binding MusicFile.Metadata.Year, Converter={StaticResource UIntToDisplayValueConverter}}" Grid.Column="2" Grid.Row="12"/>

                <Label Content="{x:Static p:Resources.Genre}" Grid.Column="0" Grid.Row="14"/>
                <ComboBox Text="{Binding MusicFile.Metadata.Genre, Converter={StaticResource StringListToStringConverter}, ConverterParameter=ListSeparator, UpdateSourceTrigger=LostFocus}" 
                            ItemsSource="{Binding Path=(domain:Genres.DefaultValues)}"
                            IsEditable="True" Grid.Column="2" Grid.Row="14"/>

                <Label Content="{x:Static p:Resources.BitRate}" Grid.Column="0" Grid.Row="16"/>
                <Label Content="{Binding MusicFile.Metadata.Bitrate, Converter={StaticResource BitrateConverter}}" Grid.Column="2" Grid.Row="16"/>

                <Label Content="{x:Static p:Resources.AlbumArtist}" Grid.Column="0" Grid.Row="18"/>
                <TextBox Text="{Binding MusicFile.Metadata.AlbumArtist}" Grid.Column="2" Grid.Row="18"/>

                <Label Content="{x:Static p:Resources.Publisher}" Grid.Column="0" Grid.Row="20"/>
                <TextBox Text="{Binding MusicFile.Metadata.Publisher}" Grid.Column="2" Grid.Row="20"/>

                <Label Content="{x:Static p:Resources.Subtitle}" Grid.Column="0" Grid.Row="22"/>
                <TextBox Text="{Binding MusicFile.Metadata.Subtitle}" Grid.Column="2" Grid.Row="22"/>

                <Label Content="{x:Static p:Resources.Composers}" Grid.Column="0" Grid.Row="24"/>
                <TextBox Text="{Binding MusicFile.Metadata.Composers, Converter={StaticResource StringListToStringConverter}}" 
                            AcceptsReturn="True" Grid.Column="2" Grid.Row="24"/>

                <Label Content="{x:Static p:Resources.Conductors}" Grid.Column="0" Grid.Row="26"/>
                <TextBox Text="{Binding MusicFile.Metadata.Conductors, Converter={StaticResource StringListToStringConverter}}" 
                            AcceptsReturn="True" Grid.Column="2" Grid.Row="26"/>
            </Grid>
        </ScrollViewer>

        <Border Height="21" Grid.Row="2" Background="{StaticResource DarkBackground}" BorderThickness="0">
            <TextBlock Text="{x:Static p:Resources.Error}" Foreground="{StaticResource DarkErrorForeground}" Margin="7,0" VerticalAlignment="Center">
                <TextBlock.Style>
                    <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding MusicFile.LoadError}" Value="{x:Null}">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </Border>

        <ProgressBar IsIndeterminate="True" Grid.Row="2" VerticalAlignment="Top">
            <ProgressBar.Visibility>
                <MultiBinding Converter="{StaticResource MusicPropertiesProgressVisibilityConverter}">
                    <Binding Path="MusicFile.IsMetadataLoaded"/>
                    <Binding Path="MusicFile.LoadError"/>
                </MultiBinding>
            </ProgressBar.Visibility>
        </ProgressBar>

        <Border Height="2" Grid.Row="2" VerticalAlignment="Top" Background="{StaticResource ErrorForeground}" BorderThickness="0">
            <Border.Style>
                <Style TargetType="Border">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding MusicFile.LoadError}" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
    </Grid>
</UserControl>
